package org.zjx.window.action;

import org.zjx.window.strategy.IStrategy;
import org.zjx.window.strategy.StrategyFactory;
import org.zjx.window.window.IWindow;
import org.zjx.window.window.impl.GameWindow;
import org.zjx.window.window.impl.LoginWindow;
import org.zjx.window.window.impl.StartWindow;

public class StrategyAction extends Action {

    public StrategyAction(IWindow targetWindow) {
        super(targetWindow, false);
    }

    @Override
    protected void doExecute() {
        if (targetWindow instanceof LoginWindow || targetWindow instanceof GameWindow || targetWindow instanceof StartWindow) {
            targetWindow.flushScreenshot();
        }

        IStrategy strategy = StrategyFactory.getInstance()
                .selectAndExecuteStrategy(targetWindow);

        IAction nextCommand = strategy.analyze(targetWindow);
        if (nextCommand != null) {
            targetWindow.submitAction(nextCommand);
        }
    }
}
